//
//  MainTabBarController.m
//  SheMeasured
//
//  Created by yqh on 2019/4/11.
//  Copyright © 2019年 xmddkj. All rights reserved.
//

#import "MainTabBarController.h"
#import "BaseNavViewController.h"
#import "BaseTabBarItem.h"

@interface MainTabBarController ()

@property (nonatomic, strong) NSArray *tabItems;

@end

@implementation MainTabBarController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        [self createTabBarItem];
        [self createTabBarItemImage];
        self.selectedIndex = 0;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)createTabBarItem {
    UINavigationController *nav_home = [[BaseNavViewController alloc] initWithRootViewController:[[NSClassFromString(@"HomeController") alloc] init]];
    
    UINavigationController *nav_sort = [[BaseNavViewController alloc] initWithRootViewController:[[NSClassFromString(@"SortController") alloc] init]];
    
    UINavigationController *nav_list = [[BaseNavViewController alloc] initWithRootViewController:[[NSClassFromString(@"ListController") alloc] init]];
    
    UINavigationController *nav_mine = [[BaseNavViewController alloc] initWithRootViewController:[[NSClassFromString(@"MineController") alloc] init]];
    
    self.viewControllers = @[nav_home, nav_sort, nav_list, nav_mine];
}

- (void)createTabBarItemImage {
    for (int i = 0; i < self.tabBar.items.count; i ++) {
        
        UITabBarItem *item = self.tabBar.items[i];
        
        BaseTabBarItem *model = self.tabItems[i];
        
        item.image = [[UIImage imageNamed:model.imageNor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:model.imageSel] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.title = model.title;
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:Main_Title_Color} forState:UIControlStateSelected];
    }
    
//    [self.tabBar setBackgroundColor:[UIColor whiteColor]];
    self.tabBar.barTintColor = [UIColor whiteColor];
}

- (NSArray *)tabItems {
    if (_tabItems == nil) {
        _tabItems = [BaseTabBarItem getTabBarItems];
    }
    return _tabItems;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
